const cloud = require('wx-server-sdk')
cloud.init()
const db = cloud.database()

exports.main = async (event, context) => {
  let tasks = await db.collection('vote')
    .where({
      available: true
    }).get()

  let todaydata = new Date()
  for(i=0; i<tasks.data.length; i++)
  {
    if (tasks.data[i].deadline <= todaydata)
    {
      await db.collection('vote').doc(tasks.data[i]._id).update({
        data: {
          available: false
        }
      })
    
    }
  }

}